package observer;

import java.util.ArrayList;
import java.util.Iterator;

public abstract class Subject {

  private ArrayList<Observer> observers;
  
  public Subject() {
    observers = new ArrayList<Observer>();
  }
  
  public void addObserver(Observer observer){
    observers.add(observer);
  }
  
  public void deleteObserver(Observer observer){
    observers.remove(observer);
  }
  
  public void notifyObserver(){
    Iterator<Observer> it = observers.iterator();
    while(it.hasNext()){
      Observer o = (Observer)it.next();
      o.update(this);
    }
  }
  
  public ArrayList<Observer> getObservers(){   
    return observers;
  }
}
